<div class="event-item clearfix" id="event-<?php echo $data->id; ?>">
	<div class="event-left">
    	<div class="event-left-header clearfix">
        	<span class="event-left-date"><?php echo date('l', strtotime($data->startdate)); ?></span>
            <span class="event-left-day pull-right"><?php echo date('d-m-Y', strtotime($data->startdate)); ?></span>
        </div>
        <div class="event-left-body">
        	<a href="<?php echo Yii::app()->createUrl('/Events/default/view', array('category'=>$data->category->url, 'url'=>$data->url)); ?>" class="clearfix" title="<?php echo $data->title; ?>">
            	<img src="<?php echo IMAGES_URL . 'events/thumbs/' . date('Ymd', strtotime($data->posteddate)) . '/' . $data->image; ?>" alt="<?php echo $data->title; ?>" width="150" />
            </a>
        </div>
    </div>
    <div class="event-right">
    	<h3 class="event-title"><?php echo CHtml::link($data->title, array('/Events/default/view', 'category'=>$data->category->url, 'url'=>$data->url), array('title'=>$data->title)); ?> <?php if ($data->status === 'P') echo '<em class="text-danger">(Sự kiện đang chờ duyệt)</em>'; ?></h3>
        <p class="event-category">
        <?php echo CHtml::link($data->category->title, array('/Events/categories/view', 'url'=>$data->category->url), array('title'=>$data->category->title)); ?>
        <?php if ($data->ticket === 'F') {
			echo CHtml::link('Miễn phí', array('/Events/categories/freeEvent'), array('title'=>'Sự kiện miễn phí', 'class'=>'event-ticket'));
		}
		elseif ($data->ticket === 'G') {
			echo CHtml::link('Ưu đãi', array('/Events/categories/giftEvent'), array('title'=>'Sự kiện ưu đãi, quà tặng', 'class'=>'event-ticket'));
		}
		else {
			echo CHtml::link('Có phí', array('/Events/categories/paidEvent'), array('title'=>'Sự kiện có phí', 'class'=>'event-ticket'));
		} ?>
        </p>
        <p class="event-time">
        	<span class="glyphicon glyphicon-time"></span>
            <?php echo date('H:i - l, \n\g\à\y d-m-Y', strtotime($data->startdate)); ?>
        </p>
        <p class="event-location">
        	<span class="glyphicon glyphicon-map-marker"></span>
			<?php if (!empty($data->locations)) {
				foreach ($data->locations as $location) {
					// Kiểm tra xem có bản ghi địa điểm hay không
					if ($location->place_id == 0) {
						// Lấy thông tin từ bản ghi EventLocations
						if (!empty($location->title)) { echo $location->title; };
						if (!empty($location->address)) { echo ', ' . $location->address; };
						if (!empty($location->ward)) { echo ', ' . $location->ward; };
						if (!empty($location->district)) { echo ', ' . $location->district; };
						if (!empty($location->city)) { echo ', ' . $location->city; };
					}
					elseif (!empty($location->place)) {
						// Lấy thông tin từ bản ghi Places
						if (!empty($location->place->title)) { echo $location->title; };
						if (!empty($location->place->location->address)) { echo ', ' . $location->place->location->address; };
						if (!empty($location->place->location->ward)) { echo ', ' . $location->place->location->ward; };
						if (!empty($location->place->location->district)) { echo ', ' . $location->place->location->district; };
						if (!empty($location->place->location->city)) { echo ', ' . $location->place->location->city; };
					}
					else {
						echo 'Xem chi tiết';
					}
				}
			}
			else {
				echo 'Xem chi tiết';
			} ?>
        </p>
        <p class="event-ticket">
        <?php if ($data->ticket === 'P'): ?>
            <span class="event-price">
                <span class="glyphicon glyphicon-usd"></span>
                <?php if (isset($data->price)) {
                    echo 'Giá từ ' . number_format($data->price->price, 0, '.', ',') . ' VNĐ';
                }
                else {
                    echo 'Liên hệ';
                } ?>
            </span>
            <span class="event-divider"></span>
            <?php endif; ?>
            <span class="event-price">
            	<span class="glyphicon glyphicon-eye-open"></span> <?php echo number_format($data->numviews, 0, '.', ','); ?> lượt xem
            </span>
        </p>
        <p class="event-update">
            <span class="glyphicon glyphicon-edit"></span> Cập nhật lúc: <?php echo ucwords(strftime('%H:%M - %A, ngày %d-%m-%Y', strtotime($data->updatedate))); ?>
        </p>
        <p class="event-update clearfix">
            <?php
            if(Yii::app()->user->id == $data->member_id){
                echo CHtml::link('Quảng cáo', array('#'), array('title'=>'Quảng cáo', 'class'=>'pull-right btn btn-danger btn-modal', 'data-toggle'=>'modal', 'data-target'=>'#createModal'));
                echo CHtml::link('Sửa', array('/Events/default/update', 'category'=>$data->category->url, 'url'=>$data->url), array('title'=>'Sửa', 'class'=>'pull-right btn btn-info'));
                echo CHtml::link('Làm mới', array('/Events/default/refresh', 'category'=>$data->category->url, 'url'=>$data->url), array('title'=>'Làm mới', 'class'=>'pull-right btn btn-success'));
            } ?>
        </p>
    </div>
</div>